﻿#ifndef VIRTUAL_DATA_H_
#define VIRTUAL_DATA_H_

#include "common.h"
#include "Event.h"
#include "VirInterface.h"

/* 处理虚拟网卡数据 */

class TapData : public Event, public VirInterface
{
public:

    TapData(const std::string& dev, std::function<void(DataCache)> func);
    virtual ~TapData();

    int init();
    int shutdown();

    int VSendData(DataCache& data, int msecond);
private:

    virtual void CycleTask();
    int send_data(const char* buff, int bufflen);
    int tun_alloc(const std::string& dev, int flags);

private:

    int                 m_socket;

    std::string                       m_ifname;
    std::function<void(DataCache)>    m_func;
};
typedef std::shared_ptr<TapData>  TapDataPtr;



#endif